package com.cooper.dao.seller;

import java.util.List;

import com.cooper.entity.DesignerEntity;
import com.cooper.pagination.PageInfo;
import com.cooper.vo.CompositeDesignerProjectVo;
import com.cooper.vo.DesignerSearchVo;
import com.cooper.vo.DesignerVo;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.Insert;
import net.paoding.rose.jade.annotation.Paged;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.Update;

@DAO
public interface DesignerDAO {

	@Insert(tableName="d_designer")
	Long addDesigner(DesignerEntity designerDo);
	
	@SQL("select * from  d_designer where id=:1")
	DesignerEntity getDesigner(Long id);
	
	@SQL("select * from  d_designer where user_id=:1")
	DesignerEntity getDesignerByUserId(Long userId);
	
	
	@Update(tableName="d_designer")
	void updateDesigner(DesignerEntity designerDo);
	
	@Paged(paramIndex=1)
	@SQL("select * from (select b.id as project_id,a.id as designer_id,a.store_name,a.seller_name,a.seller_file_id,a.favorite,a.user_id,a.email,a.tel,a.live_file_ids,b.category,b.description,b.file_id as project_file_id"
			+ ",c.id as address_id,concat(c.city_id,c.state_id,c.country_id,c.continent_id) as str_location_ids"
			+ ",concat(IFNULL(c.city_name,\"\"),IFNULL(c.state_name,\"\"),IFNULL(c.country_name,\"\"),IFNULL(c.continent_name,\"\")) as str_location_names,c.street,"
			+ "(select count(1) from d_dis_select_config where select_type='select_designer' and outer_id=a.user_id) display "
			+ "from d_designer a left join d_project_info b on (a.user_id=b.user_id and a.deleted='n' and b.deleted='n') left join d_address c on (a.id=c.outer_id and c.origin='seller_address' and a.deleted='n' and c.deleted='n') "
			+ ") tt where 1=1 "
			+ " #if(null !=:1.userId && ''!=:1.userId){ and tt.user_id=:1.userId} "
			+ " #if(null !=:1.sellerName && ''!=:1.sellerName){ and tt.seller_name like CONCAT('%',:1.sellerName,'%') } "
			+ " #if(null !=:1.display && :1.display==1){ and tt.display>=1} "
			+ " #if(null !=:1.display && :1.display==0){ and tt.display<1} "
			)
	List<CompositeDesignerProjectVo> queryDesigners(CompositeDesignerProjectVo queryParamVo, PageInfo pageInfo);
	
	@Paged(paramIndex=1)
	@SQL("select a.* from d_designer a left join d_shop_stat l on  (a.user_id = l.seller_id ) where a.seller_type=:1 "
			+ " ORDER BY (l.like_num-l.unlike_num) desc,a.gmt_modified desc"
		)
	List<DesignerVo> queryHostShops(String sellerType, PageInfo pageInfo);
	
	@SQL("select count(1) from (select b.id as project_id,a.id as designer_id,a.store_name,a.seller_name,a.seller_file_id,a.favorite,a.user_id,a.email,a.tel,a.live_file_ids,b.category,b.description,b.file_id as project_file_id"
			+ ",c.id as address_id,concat(c.city_id,c.state_id,c.country_id,c.continent_id) as str_location_ids"
			+ ",concat(IFNULL(c.city_name,\"\"),IFNULL(c.state_name,\"\"),IFNULL(c.country_name,\"\"),IFNULL(c.continent_name,\"\")) as str_location_names,c.street,"
			+ "(select count(1) from d_dis_select_config where select_type='select_designer' and outer_id=a.user_id) display "
			+ "from d_designer a left join d_project_info b on (a.user_id=b.user_id and a.deleted='n' and b.deleted='n') left join d_address c on (a.id=c.outer_id and c.origin='seller_address' and a.deleted='n' and c.deleted='n') "
			+ ") tt where 1=1 "
			+ " #if(null !=:1.userId && ''!=:1.userId){ and tt.user_id=:1.userId} "
			+ " #if(null !=:1.sellerName && ''!=:1.sellerName){ and tt.seller_name like CONCAT('%',:1.sellerName,'%') } "
			+ " #if(null !=:1.display && :1.display==1){ and tt.display>=1} "
			)
	int queryDesignersCount(CompositeDesignerProjectVo queryParamVo);
	
	@SQL("select count(*) from d_designer a where a.deleted='n'"
			+ " #if(null !=:1.sellerType && ''!=:1.sellerType){ and a.seller_type=:1.sellerType}")
	int queryDesignerCount(DesignerSearchVo searchVo);
	
	@Paged(paramIndex=1)
	@SQL("select a.id,a.user_id,a.store_name,a.seller_name,a.seller_file_id,a.company_name,a.contactor,a.favorite,"
			+ "a.brand_certificate,a.business_licence,a.passport,a.legal_passport,a.comments,"
			+ " (select zh_cn from d_location b,d_address d where b.id=d.country_id and d.origin='seller_address' and d.outer_id=a.user_id and d.deleted='n') country_name,"
			+ "(select count(*) from d_item_info b where b.deleted='n' and a.user_id=b.seller_id) item_count "
			+ " from d_designer a where a.deleted='n'"
			+ " #if(null !=:1.sellerType && ''!=:1.sellerType){ and a.seller_type=:1.sellerType}")
	List<DesignerVo> queryForList(DesignerSearchVo searchVo, PageInfo pageInfo);
	
	
}
